<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Open a persistent connection to a CUBRID server</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-pconnect-with-url.html">cubrid_pconnect_with_url</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-prepare.html">cubrid_prepare</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.cubrid-pconnect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_pconnect</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.1)</p><p class="refpurpose"><span class="refname">cubrid_pconnect</span> &mdash; <span class="dc-title">Open a persistent connection to a CUBRID server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-pconnect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>cubrid_pconnect</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>  
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>  
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$dbname</code></span>  
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$userid</code></span>  
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$passwd</code></span>  
  ]] )</div>

  <p class="para rdfs-comment">
   Establishes a persistent connection to a CUBRID server.
  </p>
  <p class="para">
   <span class="function"><strong>cubrid_pconnect()</strong></span> acts very much like
   <span class="function"><a href="function.cubrid-connect.html" class="function">cubrid_connect()</a></span> with two major differences. 
  </p>
  <p class="para">
   First, when connecting, the function would first try to find a (persistent)
   link that&#039;s already open with the same host, port, dbname and userid. If
   one is found, an identifier for it will be returned instead of opening a
   new connection.
  </p>
  <p class="para">
   Second, the connection to the SQL server will not be closed when the
   execution of the script ends.  Instead, the link will remain open for
   future use (<span class="function"><a href="function.cubrid-close.html" class="function">cubrid_close()</a></span> or
   <span class="function"><a href="function.cubrid-disconnect.html" class="function">cubrid_disconnect()</a></span> will not close links established by
   <span class="function"><strong>cubrid_pconnect()</strong></span>).
  </p>
  <p class="para">
   This type of link is therefore called &#039;persistent&#039;.
  </p>
 </div>


  <div class="refsect1 parameters" id="refsect1-function.cubrid-pconnect-parameters">
 <h3 class="title">参数</h3>
 <p class="para">
  <dl>

   
    <dt>
<em><code class="parameter">host</code></em></dt>

    <dd>
<p class="para">Host name or IP address of CUBRID CAS server.</p></dd>

   
   
    <dt>
<em><code class="parameter">port</code></em></dt>

    <dd>
<p class="para">Port number of CUBRID CAS server (BROKER_PORT configured in $CUBRID/conf/cubrid_broker.conf).</p></dd>

   
   
    <dt>
<em><code class="parameter">dbname</code></em></dt>

    <dd>
<p class="para">Name of database.</p></dd>

   
   
    <dt>
<em><code class="parameter">userid</code></em></dt>

    <dd>
<p class="para">User name for the database.</p></dd>

   
   
    <dt>
<em><code class="parameter">passwd</code></em></dt>

    <dd>
<p class="para">User password.</p></dd>

   
  </dl>

  </p>
 </div>


  <div class="refsect1 returnvalues" id="refsect1-function.cubrid-pconnect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    Connection identifier, when process is successful. 
  </p>
    <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-pconnect-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1025">
   <p><strong>Example #1 <span class="function"><a href="function.cubrid-connect.html" class="function">cubrid_connect()</a></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CUBRID&nbsp;PHP&nbsp;Version:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">cubrid_version</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"dba"</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Connect&nbsp;Error&nbsp;('</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">cubrid_error_code</span><span style="color: #007700">()&nbsp;.</span><span style="color: #DD0000">')'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">cubrid_error_msg</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #0000BB">$db_params&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_db_parameter</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br />while&nbsp;(list(</span><span style="color: #0000BB">$param_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_value</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$db_params</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_value</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$server_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_server_info</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$client_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_client_info</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Server&nbsp;Info:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$server_info</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Client&nbsp;Info:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$client_info</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$charset&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_charset</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CUBRID&nbsp;Charset:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$charset</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
CUBRID PHP Version:            9.1.0.0001

PARAM_ISOLATION_LEVEL          3
LOCK_TIMEOUT                   -1
MAX_STRING_LENGTH              1073741823
PARAM_AUTO_COMMIT              1

Server Info:                   9.1.0.0212
Client Info:                   9.1.0

CUBRID Charset:                iso8859-1
</pre></div>
   </div>
  </div>
 </div>

 
   <div class="refsect1 seealso" id="refsect1-function.cubrid-pconnect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.cubrid-connect.html" class="function" rel="rdfs-seeAlso">cubrid_connect()</a> - Open a connection to a CUBRID Server</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-connect-with-url.html" class="function" rel="rdfs-seeAlso">cubrid_connect_with_url()</a> - Establish the environment for connecting to CUBRID server</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-pconnect-with-url.html" class="function" rel="rdfs-seeAlso">cubrid_pconnect_with_url()</a> - Open a persistent connection to CUBRID server</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-disconnect.html" class="function" rel="rdfs-seeAlso">cubrid_disconnect()</a> - Close a database connection</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-close.html" class="function" rel="rdfs-seeAlso">cubrid_close()</a> - Close CUBRID connection</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-pconnect-with-url.html">cubrid_pconnect_with_url</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-prepare.html">cubrid_prepare</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
